var dosthService = require('../services/dosthService');
var messageUtil = require('../common/utils/messageUtil');
var toolUtil = require('../common/utils/toolUtil');




exports.findCompatriots = function(req, res) {

    logger.debug('findCompatriots: ' +  req.body);
    logger.debug('findCompatriots: ' +  req.params);

    dosthService.findCompatriotsService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when findCompatriots...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when findCompatriots...'));
        }else {
            var data = {
                totalPage: results[0],
                list: results[1]
            };
            logger.debug('data: ');
            logger.debug(data);
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};


exports.findPlaymates = function(req, res) {


    dosthService.findPlaymatesService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when findPlaymates...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when findPlaymates...'));
        }else {
            var data = {
                totalPage: results[0],
                list: results[1]
            };
            logger.debug('data: ');
            logger.debug(data);
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};


exports.dosthTogether = function(req, res) {


    dosthService.dosthTogetherService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when dosthTogether...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when dosthTogether...'));
        }else {
            var data = {
                totalPage: results[0],
                list: results[1]
            };
            logger.debug('data: ');
            logger.debug(data);
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};


exports.dosthConfig = function(req, res) {


    dosthService.dosthConfigService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when dosthConfig...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when dosthConfig...'));
        }else {
            var data = {
                totalPage: results[0],
                list: results[1]
            };
            logger.debug('data: ');
            logger.debug(data);
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};



exports.dosthConfigAdd = function(req, res) {


    dosthService.dosthConfigAddService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when dosthConfigAdd...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when dosthConfigAdd...'));
        }else {
            var data = {
                totalPage: results[1],
                list: results[2]
            };
            logger.debug('data: ');
            logger.debug(data);
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};

exports.dosthConfigDelete = function(req, res) {


    dosthService.dosthConfigDeleteService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when dosthConfigDelete...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when dosthConfigDelete...'));
        }else {
            var data = {
                totalPage: results[1],
                list: results[2]
            };
            logger.debug('data: ');
            logger.debug(data);
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};

exports.dosthGetType = function(req, res) {


    dosthService.dosthGetTypeeService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when dosthGetType...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when dosthGetType...'));
        }else {
            var data = results[0];
            logger.debug('data: ');
            logger.debug(data);
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};


exports.test = function(req, res) {


    dosthService.testService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when test...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when test...'));
        }else {
            var data = results[0];
            logger.debug('data: ');
            logger.debug(data);
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};


